package com.ruoyi.shopping_products.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shopping_products.domain.PdUsers;
import com.ruoyi.shopping_products.service.IPdUsersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商城用户Controller
 * 
 * @author lzy
 * @date 2023-10-28
 */
@RestController
@RequestMapping("/shopping_products/users")
public class PdUsersController extends BaseController
{
    @Autowired
    private IPdUsersService pdUsersService;

    /**
     * 查询商城用户列表
     */
    @PreAuthorize("@ss.hasPermi('shopping_products:users:list')")
    @GetMapping("/list")
    public TableDataInfo list(PdUsers pdUsers)
    {
        startPage();
        List<PdUsers> list = pdUsersService.selectPdUsersList(pdUsers);
        return getDataTable(list);
    }

    /**
     * 导出商城用户列表
     */
    @PreAuthorize("@ss.hasPermi('shopping_products:users:export')")
    @Log(title = "商城用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PdUsers pdUsers)
    {
        List<PdUsers> list = pdUsersService.selectPdUsersList(pdUsers);
        ExcelUtil<PdUsers> util = new ExcelUtil<PdUsers>(PdUsers.class);
        util.exportExcel(response, list, "商城用户数据");
    }

    /**
     * 获取商城用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('shopping_products:users:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pdUsersService.selectPdUsersById(id));
    }

    /**
     * 新增商城用户
     */
    @PreAuthorize("@ss.hasPermi('shopping_products:users:add')")
    @Log(title = "商城用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PdUsers pdUsers)
    {
        return toAjax(pdUsersService.insertPdUsers(pdUsers));
    }

    /**
     * 修改商城用户
     */
    @PreAuthorize("@ss.hasPermi('shopping_products:users:edit')")
    @Log(title = "商城用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PdUsers pdUsers)
    {
        return toAjax(pdUsersService.updatePdUsers(pdUsers));
    }

    /**
     * 删除商城用户
     */
    @PreAuthorize("@ss.hasPermi('shopping_products:users:remove')")
    @Log(title = "商城用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pdUsersService.deletePdUsersByIds(ids));
    }
}
